const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goods_list: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  onShow: function () {
    wx.showLoading({
      title: '加载中……',
    })
    this.getGoodsList();
  },

  getGoodsList: function () {
    let that = this;
    app.ihttpGet('https://www.58zltc.com/api.php/Goods/index/type/jiancai/openid/' + app.globalData.openid, function (res) {
      that.setData({
        goods_list: res.data
      })
      wx.hideLoading();
    });
  },
  editGood: function (e) {
    const data = e.target.dataset;
    wx.navigateTo({
      url: 'add?type=' + data.type + '&id=' + data.id,
    })
  },
  delGood: function (e) {
    var that = this;
    wx.showModal({
      title: '提示',
      content: '确定要删除该商品？',
      success: function (res) {
        if (res.confirm) {
          wx.showLoading({
            title: '删除中……',
          })
          app.ihttpGet('https://www.58zltc.com/api.php/Goods/del/openid/' + app.globalData.openid + '/id/' + e.target.dataset.id, function (res) {
            wx.showModal({
              title: '提示',
              content: res.data.err_msg,
              showCancel: false,
              success: function () {
                if (res.data.err_code === 0) {
                  that.getGoodsList();
                }
              }
            })
          });
        }
      }
    })
  },
  backto: function () {
    wx.navigateBack({})
  }
})